import {
	requestPayment
} from '@/utils/app.js'
export default {
	data() {
		return {
			goods: {},
			goodsId: '',
			agree: true,
			orderId: ''
		};
	},
	onLoad(options) {
		this.goods = JSON.parse(decodeURIComponent(options.goods))
		this.goodsId = options.goodsId
	},
	methods: {
		// 去支付
		async onPay() {
			if (!this.agree) {
				this.$toast('请先阅读并同意用户协议')
				return
			}
			this.$refs.animate.open()
		},
		async onRecharge(money) {
			var res = await this.$get('server/index/buymanghegoods', {
				goodsid: this.goodsId,
			});
			
			if (res.errcode != 0) {
				this.$toast(res.errmsg);
				return;
			}

			requestPayment(res, this.payType)
				.then(() => {
					this.$redirectTo('pages/manghe/result/result', {
						orderid: this.orderId
					})
				})
				.catch(err => {
					console.log('zhifushibai====')
					console.log(err)
					this.$toast('订单未支付')
				})
				.finally((msg) => {
					// this.$toast('取消支付')
				})
		},
		toAgreement(type) {
			this.$navTo('pages/mine/agreement/agreement', {
				type: type
			});
		},
	}
}
